package com.szss.springbootfirst.mq;

import com.szss.springbootfirst.config.RabbitMQConfig;
import com.szss.springbootfirst.entity.User;
import com.szss.springbootfirst.service.IUserService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wcx
 * @date 2023/2/10 15:16
 */

@Component
public class MessageProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private IUserService userService;

    public void sendMessage(){
        List<User> userList = userService.findAll();
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_DIRECT,RabbitMQConfig.EMAIL_KEY,userList);
    }
}
